home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
graphics
/
qrt.lzh
/
INOUT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-16
|
24KB
|
1,119 lines
/**********************************************************
object loader language
**********************************************************/
#define IODEBUG 1
#include "qrt.h"
#include "pattern.h"
OBJ_PTR new_obj(), Get_Object(), Get_Primitive(),
Get_Instance_Of();
PATTERN_PTR Attach_Pattern(), Get_Pattern();
char *malloc();
# ifdef AMIGA
float atof();
# endif
/**********************************************************
External declarations from lexer
**********************************************************/
float IsPos();
float Get_Next_Num();
short Get_Color_Val();
char *Get_Next_Name();
/**********************************************************
Global input line number. If negative, error rountines
will not report line number (already reached EOF).
**********************************************************/
extern int linenumber;
/**********************************************************
Load the entire world from standard input
**********************************************************/
int LoadWorld() /* load world from stdio */
{
linenumber = 1;
if((THEWORLD.stack=Get_Object())==NULL)
Error(ILLEGAL_OBJECT,201);
linenumber = -1;
return(TRUE);
}
/**********************************************************
Get an object and return a pointer to it. If it is
not an object, but some other world attribute
specification, note it, but keep trying until an
object is found or end of input is encountered.
This is slighly hacked out, but it works for now.
It calls itself recursively sometimes.
**********************************************************/
OBJ_PTR Get_Object() {
char str[SLEN], *name;
OBJ_PTR newobj, queue, temp;
VECTOR loc,rad,d,v3, upper, lower;
CINFO cinfo;
int found;
name=NULL; queue=NULL;
VectEqZero(&loc);
VectEqZero(&rad);
VectEqZero(&d);
VectEqZero(&v3);
VectEqZero(&upper);
VectEqZero(&lower);
if (feof(stdin)) return(NULL);
while (!feof(stdin)) {
GetToken(str); found = FALSE;
# ifdef IODEBUG
printf("GETOBJECT: token=%s\n",str);
# endif
if (GetAttrib(str))
found = TRUE;
if (strcmp(str,"BEGIN_INSTANCES")==0) {
found = TRUE;
THEWORLD.instances = Get_Object();
}
if (strcmp(str,"END_INSTANCES")==0) {
# ifdef ROBUST
if (queue==NULL) Error(SYNTAX_ERROR,205);
# endif
found = TRUE;
return(queue);
}
if (strcmp(str,"END_BBOX")==0) {
# ifdef ROBUST
if (queue==NULL) Error(SYNTAX_ERROR,206);
# endif
found = TRUE;
return(queue);
}
if (strcmp(str,"BEGIN_BBOX")==0) {
newobj=new_obj(BBOX,&loc,&rad,&d,&v3,&cinfo,NULL,NULL,name,
&upper, &lower,
(float)0.0, (float)0.0, (float)0.0);
newobj->child = Get_Object();
newobj->nextobj = queue;
queue = newobj;
found = TRUE;
}
if (strcmp(str,"NAME")==0) {
name=Get_Next_Name();
found = TRUE;
}
if ((temp=Get_Primitive(str))!=NULL) {
found = TRUE;
temp->nextobj=queue;
queue = temp;
}
if (!found && !feof(stdin)) Error(SYNTAX_ERROR,207);
}
return(queue);
}
/**********************************************************
Load default color info
**********************************************************/
def_colorinfo(cinfo)
CINFO_PTR cinfo;
{
copy_colorinfo(cinfo,&(def.cinfo));
}
/**********************************************************
Copy color info
**********************************************************/
copy_colorinfo(c1,c2)
CINFO_PTR c1,c2;
{
if (c1 == NULL) return;
SVectEQ(&(c1->amb),&(c2->amb));
SVectEQ(&(c1->diff),&(c2->diff));
SVectEQ(&(c1->mirror),&(c2->mirror));
SVectEQ(&(c1->trans),&(c2->trans));
VectEQ(&(c1->density),&(c2->density));
c1->fuzz = c2->fuzz;
c1->index = c2->index;
c1->dither = c2->dither;
c1->sreflect = c2->sreflect;
c1->reflect = c2->reflect;
}
/**********************************************************
Get defaults from input file
**********************************************************/
int Get_Default()
{
char str[SLEN];
int end, found;
end=0;
GetLeftParen();
while (!end && !feof(stdin)) {
GetToken(str);
# ifdef IODEBUG
printf("GETDEFAULT : token=%s\n",str);
# endif
found = GetOpt(str,&(def.cinfo));
if (strcmp(str,"NO_SHADOW")==0) {
def.shadow = FALSE;
found = TRUE;
}
if (strcmp(str,"NO_LAMP")==0) {
def.vlamp = FALSE;
found = TRUE;
}
if (strcmp(str,"THRESHOLD")==0) {
def.threshold = IsPos(Get_Next_Num());
found = TRUE;
}
if (strcmp(str,")")==0) { end = 1; found = TRUE;}
if (!found) Error(UNDEFINED_PARAM,209);
}
return(TRUE);
}
/**********************************************************
Get object options
**********************************************************/
int GetOpt(str,cinfo)
char str[];
CINFO_PTR cinfo;
{
int found;
found = FALSE;
if (strcmp(str,"AMB")==0) {
GetSVector(&(cinfo->amb));
found = TRUE;
}
if (strcmp(str,"DIFF")==0) {
GetSVector(&(cinfo->diff));
found = TRUE;
}
if (strcmp(str,"MIRROR")==0) {
GetSVector(&(cinfo->mirror));
found = TRUE;
}
if (strcmp(str,"TRANS")==0) {
GetSVector(&(cinfo->trans));
found = TRUE;
}
if (strcmp(str,"DENSITY")==0) {
GetVector(&(cinfo->density));
found = TRUE;
}
if (strcmp(str,"FUZZ")==0) {
cinfo->fuzz = Get_Color_Val();
found = TRUE;
}
if (strcmp(str,"INDEX")==0) {
cinfo->index = IsPos(Get_Next_Num());
found = TRUE;
}
if (strcmp(str,"DITHER")==0) {
cinfo->dither = (short)IsPos(Get_Next_Num());
found = TRUE;
}
if (strcmp(str,"SREFLECT")==0) {
cinfo->sreflect = IsPos(Get_Next_Num());
found = TRUE;
}
if (strcmp(str,"REFLECT")==0) {
cinfo->reflect = Get_Color_Val();
found = TRUE;
}
return(found);
}
/**********************************************************
Load a sphere and return pointer to it
**********************************************************/
OBJ_PTR GetSphere()
{
char str[SLEN], *name;
VECTOR loc, rad, d, v3, upper, lower;
float xmult, ymult;
CINFO cinfo;
OBJ_PTR newobj;
PATTERN_PTR pattern, remove;
int end, f, found;
end=f=0;
def_colorinfo(&cinfo);
xmult=ymult=1;
pattern = remove = NULL;
name = NULL;
GetLeftParen();
while (!end && !feof(stdin)) {
GetToken(str);
# ifdef IODEBUG
printf("GETSPHERE : token=%s\n",str);
# endif
found = GetOpt(str,&cinfo);
if ((strcmp(str,"POS")==0) ||
(strcmp(str,"LOC")==0) ||
(strcmp(str,"POSITION")==0) ||
(strcmp(str,"LOCATION")==0)) {
GetVector(&loc);
f|=1; found = TRUE;
}
if (strcmp(str,"RADIUS")==0) {
rad.x = IsPos(Get_Next_Num());
f|=2; found = TRUE;
}
if (strcmp(str,"PATTERN")==0) {
pattern = Attach_Pattern();
found = TRUE;
}
if (strcmp(str,"REMOVE")==0) {
remove = Attach_Pattern();
found = TRUE;
}
if (strcmp(str,"XMULT")==0) {
xmult = IsPos(Get_Next_Num());
found=TRUE;
}
if (strcmp(str,"YMULT")==0) {
ymult = IsPos(Get_Next_Num());
found=TRUE;
}
if (strcmp(str,"NAME")==0) {
name=Get_Next_Name();
found = TRUE;
}
if (strcmp(str,")")==0) { end = 1; found = TRUE; }
if (!found) Error(UNDEFINED_PARAM,211);
}
if (f!=3) Error(TOO_FEW_PARMS,212);
rad.y=rad.z=0;
VectEqZero(&d);
VectEqZero(&upper);
VectEqZero(&lower);
newobj=new_obj(SPHERE,&loc,&rad,&d,&v3,&cinfo,pattern,
remove,name,
&upper, &lower, 0.0, xmult, ymult);
THEWORLD.objcount++;
return(newobj);
}
/**********************************************************
Load lamp and attach to world
*************